package com.relax.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
@Aspect
public class AspectDemo {

    @Before("execution(* com.relax.aop.*.methodAop(..))")
    public void before() {
        System.out.println("APO 的 before 方法执行");
    }


    @After("execution(* com.relax.aop.*.methodAop(..))")
    public void after() {
        System.out.println("APO 的 After 方法执行");
    }


    @AfterReturning("execution(* com.relax.aop.*.methodAop(..))")
    public void afterReturning() {
        System.out.println("APO 的 AfterReturning 方法执行");
    }


    @AfterThrowing("execution(* com.relax.aop.*.methodAop(..))")
    public void afterThrowing() {
        System.out.println("APO 的 AfterThrowing 异常环绕 方法执行");
    }

    @Around("execution(* com.relax.aop.*.methodAop(..))")
    public void around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("APO 的 Around 前置通知 方法执行,参数:" +  Arrays.toString(joinPoint.getArgs()));
        Object result = joinPoint.proceed();
        System.out.println("APO 的 Around 后置通知 方法执行,参数:" +  Arrays.toString(joinPoint.getArgs()));
    }
}
